#include "hal.h"
#include "relay.h"



/**********************************************************************************
 * Descrição:
 *
 * Paramêtro(s):
 *					-
 * Retorno:
 *					-
 **********************************************************************************/
void relay_init (void){
	//controle do rele da bomba dagua
	GPIO_SetDir    (PORT_RELAYS,PORT_RELAYS, 1);
	GPIO_ClearValue(PORT_RELAYS,PORT_RELAYS   );//inicializa tudo em zero
	//controle inversor de frequencia
	GPIO_SetDir    (PORT_RELAYS_INV,RELAYS_INV, 1); //inicializa os pinos de control do inversor
	GPIO_ClearValue(PORT_RELAYS_INV,PORT_RELAYS   );//inicializa tudo em zero
	//controle motor do bloco e do braco
	GPIO_SetDir    (PORT_MOTORES,RELAYS_MOTORES, 1); //inicializa os pinos de controle do motor blo e braco
	GPIO_ClearValue(PORT_MOTORES,RELAYS_MOTORES   );//inicializa tudo em zer
	//controle da PONTEH
	GPIO_SetDir    (PORT_PONTEH,RELAYS_PONTEH, 1);
	GPIO_ClearValue(PORT_PONTEH,RELAYS_PONTEH   ); //Ter cuidado ao incializar a ponte H
        ParadaMotorMola();
} 

/**********************************************************************************
 * Descrição:
 *
 * Paramêtro(s):
 *					-
 * Retorno:
 *					-
 **********************************************************************************/
void relay_active (uint8_t Port,uint32_t relay){
	GPIO_SetValue(Port,relay);
}

/**********************************************************************************
 * Descrição:
 *
 * Paramêtro(s):
 *					-
 * Retorno:
 *					-
 **********************************************************************************/
void relay_deactive (uint8_t Port,uint32_t relay){

	GPIO_ClearValue(Port,relay);
}
/**********************************************************************************
 * Descrição:
 *
 * Paramêtro(s):
 *					-
 * Retorno:
 *					-
 **********************************************************************************/
 void AvancoMotorMola(void){
  relay_active(PORT_PONTEH,(RELAY_AVANCO1|RELAY_RECUO2));

  relay_deactive(PORT_PONTEH,(RELAY_RECUO1|RELAY_AVANCO2));

 }

 /**********************************************************************************
  * Descrição:
  *
  * Paramêtro(s):
  *					-
  * Retorno:
  *					-
  **********************************************************************************/
  void RecuoMotorMola(void){

  relay_deactive(PORT_PONTEH,(RELAY_AVANCO1|RELAY_RECUO2));

  relay_active(PORT_PONTEH,(RELAY_RECUO1|RELAY_AVANCO2));

  }


 /**********************************************************************************
  * Descrição:
  * 
  * Paramêtro(s):
  *					-
  * Retorno:
  *					-
  **********************************************************************************/
  void ParadaMotorMola(void){
  relay_deactive(PORT_PONTEH,(RELAY_AVANCO1));
  relay_deactive(PORT_PONTEH,(RELAY_RECUO1));
  relay_active(PORT_PONTEH,(RELAY_RECUO2|RELAY_AVANCO2));
  }